package esempio.dao;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import esempio.domain.Client;




@Repository
public class ClientDAOImplNoTemplate implements ClientDAO {
	
	//private SessionFactory sessionFactory;
	
	private HibernateTemplate hibernateTemplate;

	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		hibernateTemplate = new HibernateTemplate(sessionFactory);
	}

	@Transactional(readOnly = false)
	public void saveClient(Client client) {
		hibernateTemplate.saveOrUpdate(client);

	}

	@Transactional(readOnly = false)
	public void deleteClient(Client client) {
		hibernateTemplate.delete(client);

	}

	@SuppressWarnings("unchecked")
	public List<Client> getAllClient(Client client) {
		return (List<Client>) hibernateTemplate.find("from "
				+ Client.class.getName());
	}

	public Client selectUserById(long clientId) {
		return hibernateTemplate.get(Client.class, clientId);
	}

	@Override
	public List<Client> listClient() {
		// TODO Auto-generated method stub
		return null;
	}

	
	

	

}
